

package jetbrains.buildServer.server.rest;

import jetbrains.buildServer.serverSide.BuildServerAdapter;
import jetbrains.buildServer.serverSide.SBuildServer;
import jetbrains.buildServer.web.impl.RestApiFacade;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

/**
 * There is a dependency in the core which needs to be notified when this plugin is unloaded.
 * In order to avoid creating any additional dependency on this plugin in the core (e.g. listne for lifecycle), we notify the core ourselves on plugin unload.
 */
@Component
public class PluginUnloadListener extends BuildServerAdapter {
  private final RestApiFacade myRestFacadeInCore;

  public PluginUnloadListener(@NotNull SBuildServer server, @NotNull RestApiFacade restFacadeInCore) {
    myRestFacadeInCore = restFacadeInCore;
    server.addListener(this);
  }

  @Override
  public void serverShutdown() {
    myRestFacadeInCore.forgetRestController();
  }
}